
Page({
  /**
   * 页面的初始数据
   */
  data: {
    setOneselfRaiseDotlist: [],   //自提点列表数据
    userId: '',
    apiHost: '',
    id:'',
    length:7,      //分页条数
    start:0        //从第几页开始
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var userId = wx.getStorageSync('userId');
    var apiHost = wx.getStorageSync('apiHost');
    // var userId = '2274c839ea984aacb4f1806323a96a0d';
    this.setData({
      userId: userId,
      apiHost: apiHost
    })
    that.setOneselfRaiseDotlist();//自提点列表数据
  },
  //自提点列表数据
  setOneselfRaiseDotlist: function () {
    wx.showLoading({
      title: '加载中',
      icon: 'loading',
      mask: true
    })
    var that = this;
    var start = that.data.start;
    var length = that.data.length;
    var userId = that.data.userId;
    var apiHost = that.data.apiHost;
    wx.request({
      url: apiHost + 'hpp/self/lifting/list',
      data: {
        userId: userId,
        start: start,
        length: length
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (data) {
        var code = data.data.code;
        if (code == '10000') {
          var data = data.data.data;
          that.setData({
            setOneselfRaiseDotlist: data
          })
        } else {
          wx.showToast({
            title: data.data.msg,
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
        // 隐藏加载框  
        wx.hideLoading();
      },
      fail: function () {
        wx.hideLoading();
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000,
          mask: true
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  //下拉加载更多
  onReachBottom: function () {
    var that = this;
    // 显示加载图标  
    wx.showLoading({
      title: '玩命加载中',
      icon: 'loading',
      mask: true
    })

    var start = that.data.start;
    var length = that.data.length;
    var userId = that.data.userId;
    var apiHost = that.data.apiHost;
    // 页数+1  
    var start = start+1
    that.setData({
      start: start
    })
    wx.request({
      url: apiHost + 'hpp/self/lifting/list',
      data: {
        start: start,
        length: length,
        userId: userId
      },
      // 请求头部  
      header: {
        'content-type': 'application/json'
      },
      success: function (data) {
        // console.log(data.data.code)
        var code = data.data.code;
        var msg = data.data.msg;

        if (code == '10000') {
          var data = data.data.data;

          // 回调函数
          if (data != '') {
            var moment_list = that.data.setOneselfRaiseDotlist;
            for (var i = 0; i < data.length; i++) {
              moment_list.push(data[i]);
            }
            // console.log(moment_list)
            // 设置数据  
            that.setData({
              setOneselfRaiseDotlist: moment_list
            })
            // 隐藏加载框  
            wx.hideLoading();
          } else {
            // 隐藏加载框  
            wx.hideLoading();
            wx.showToast({
              title: '没有更多数据',
              icon: 'none',
              duration: 2000,
              mask: true
            })
          }
        } else {
          wx.showToast({
            title: msg,
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
      },
      fail: function () {
        wx.showToast({
          title: '网络异常',
          icon: 'none',
          duration: 2000,
          mask: true
        })
      }

    })

  },
  /**
   * 选择自提点
   */
  select:function(e){
    var that = this;
    var selectContent = e.currentTarget.dataset;
    var index = selectContent.index;                              //选中radio的第几个

    var setOneselfRaiseDotlist = that.data.setOneselfRaiseDotlist;
    var List = setOneselfRaiseDotlist[index];

    wx.showLoading({
      title: '跳转中',
      icon: 'loading',
      mask: true
    });
    wx.redirectTo({
      url: '../../../Collage/ordinaryCollage/payment/payment?setOneselfRaiseDot=' + JSON.stringify(List),
      success: function () {
        wx.hideLoading();   //隐藏加载loading
      },
    });

    that.setData({
      id: List.id
    })
  }
})